﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
using FlexiGrid;
using FlexiGridHelper;

namespace Golf.WebUI.HttpHandler.Coupons
{
    /// <summary>
    /// CouponsList 的摘要说明
    /// </summary>
    public class CouponsList : IHttpHandler
    {
        Golf.BLL.Golf_Coupons coupns = new BLL.Golf_Coupons();

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //引入序列化
            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Golf.Model.Golf_Coupons> list = new List<Model.Golf_Coupons>();

            PageView pageview = new PageView(context);
            //获取分页数据集 调用的存储过程
            DataSet ds = coupns.GetList(pageview.PageSize, pageview.PageIndex, "0=0");
            //构建表格
            DataTable dt = new DataTable();
            //构建列
            DataColumn dc0 = new DataColumn("Id", typeof(string));
            DataColumn dc1 = new DataColumn("CouponsType", typeof(string));
            DataColumn dc2 = new DataColumn("CouponsNumber", typeof(string));
            DataColumn dc3 = new DataColumn("CouponsPassWord", typeof(string));
            DataColumn dc4 = new DataColumn("CouponsFacevalue", typeof(string));
            DataColumn dc5 = new DataColumn("IsRestriction", typeof(string));
            DataColumn dc6 = new DataColumn("CouponsRestriction", typeof(string));
            DataColumn dc7 = new DataColumn("CouponsState", typeof(string));
            DataColumn dc8 = new DataColumn("UserServiceTime", typeof(string));
            DataColumn dc9 = new DataColumn("PastdueTime", typeof(string));
            DataColumn dc10 = new DataColumn("UserId", typeof(string));
            DataColumn dc11= new DataColumn("UserOrderId", typeof(string));
            DataColumn dc12 = new DataColumn("UserOrderNumber", typeof(string));
            DataColumn dc13= new DataColumn("CreateTime", typeof(string));

            dt.Columns.AddRange(new DataColumn[]{dc0,dc1,dc2,dc3,dc4,dc5,dc6,dc7,dc8,dc9,dc10,dc11,dc12,dc13});
            list = coupns.DataTableToList(ds.Tables[0]);
            //填充数据
            foreach (var item in list)
            {
                //兴建行
                DataRow dr = dt.NewRow();
                dr["Id"] = item.Id;
                dr["CouponsType"] = item.CouponsType;
                dr["CouponsNumber"] = item.CouponsNumber;
                dr["CouponsPassWord"] = item.CouponsPassWord;
                dr["CouponsFacevalue"] = item.CouponsFacevalue;
                dr["IsRestriction"] = item.IsRestriction;
                dr["CouponsRestriction"] = item.CouponsRestriction;
                dr["CouponsState"] = item.CouponsState;
                dr["UserServiceTime"] = item.UserServiceTime;
                dr["UserId"] = item.UserId;
                dr["UserOrderId"] = item.UserOrderId;
                dr["UserOrderNumber"] = item.UserOrderNumber;
                dr["CreateTime"] = item.CreateTime;
                dt.Rows.Add(dr);
            }
            //调用转
            context.Response.Write(js.Serialize(new GetDataHelper().GetFlexiGridData(pageview, dt, list.Count)));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}